{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import os\n",
    "import time\n",
    "import pickle\n",
    "import cv2\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.image as mpimg\n",
    "\n",
    "from keras import backend as K\n",
    "from keras import applications\n",
    "from keras.preprocessing.image import ImageDataGenerator\n",
    "from keras import optimizers\n",
    "from keras.models import Sequential, Model, load_model \n",
    "from keras.layers import Dropout, Flatten, Dense, GlobalAveragePooling2D, Input\n",
    "from keras import backend as k \n",
    "from keras.callbacks import ModelCheckpoint, LearningRateScheduler, TensorBoard, EarlyStopping\n",
    "from keras.optimizers import Adam, RMSprop, SGD\n",
    "from keras.preprocessing.image import ImageDataGenerator\n",
    "\n",
    "from sklearn.model_selection import cross_val_score\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.pipeline import Pipeline\n",
    "from sklearn.svm import SVC\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "from skimage.transform import resize\n",
    "from sklearn.svm import SVC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels = []\n",
    "feature_list = []\n",
    "feature_dict=pickle.load(open('features_till_flatten_validation.pkl','rb'))\n",
    "names = [0,1]\n",
    "for cat,features  in feature_dict.items():\n",
    "    labels.extend([int(cat)] * len(features))\n",
    "    feature_list.append(features)\n",
    "feature_list = np.concatenate(feature_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: [array([[0.000000e+00, 5.356683e+22, 0.000000e+00, ..., 0.000000e+00,\n",
       "          7.275162e+21, 0.000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.3789174e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.4159007e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.5601436e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.4496704e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.5435965e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.4304766e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.3200550e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.6706124e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.1942667e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.1939757e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.5420766e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.4194012e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.2435365e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.9091439e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.000000e+00, 4.932962e+22, 0.000000e+00, ..., 0.000000e+00,\n",
       "          6.906693e+21, 0.000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.3277417e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.5608851e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.4138519e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.5298643e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.4657842e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.5034732e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.0298389e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.4615734e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.000000e+00, 5.264470e+22, 0.000000e+00, ..., 0.000000e+00,\n",
       "          6.620557e+21, 0.000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.4468835e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.5486331e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.1427352e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.2748604e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.3383355e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.4481110e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.4615171e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.4197446e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.3046261e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.2749876e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.000000e+00, 5.193179e+22, 0.000000e+00, ..., 0.000000e+00,\n",
       "          6.988037e+21, 0.000000e+00]], dtype=float32),\n",
       "  array([[0.000000e+00, 5.257394e+22, 0.000000e+00, ..., 0.000000e+00,\n",
       "          7.238006e+21, 0.000000e+00]], dtype=float32),\n",
       "  array([[0.000000e+00, 4.886876e+22, 0.000000e+00, ..., 0.000000e+00,\n",
       "          6.842348e+21, 0.000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.3700634e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.4230885e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.000000e+00, 5.167172e+22, 0.000000e+00, ..., 0.000000e+00,\n",
       "          7.415102e+21, 0.000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.3335707e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.4269914e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 5.3965927e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          7.5033916e+21, 0.0000000e+00]], dtype=float32)],\n",
       " 1: [array([[0.0000000e+00, 4.5674535e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.2906882e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 4.5963341e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.3147633e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.000000e+00, 4.594490e+22, 0.000000e+00, ..., 0.000000e+00,\n",
       "          6.303606e+21, 0.000000e+00]], dtype=float32),\n",
       "  array([[0.000000e+00, 4.393467e+22, 0.000000e+00, ..., 0.000000e+00,\n",
       "          6.026441e+21, 0.000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 4.5957158e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.3098865e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 4.5834863e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.3090178e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 4.6460543e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.3887957e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 4.5924687e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.3135513e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 4.3997187e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.0483670e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.000000e+00, 4.589118e+22, 0.000000e+00, ..., 0.000000e+00,\n",
       "          6.276252e+21, 0.000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 4.5834912e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.2912832e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 4.3951566e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.0275209e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 4.6142846e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.3557590e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 4.4605074e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.1411259e+21, 0.0000000e+00]], dtype=float32),\n",
       "  array([[0.0000000e+00, 4.6465286e+22, 0.0000000e+00, ..., 0.0000000e+00,\n",
       "          6.3877976e+21, 0.0000000e+00]], dtype=float32)]}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "feature_list1=[]\n",
    "for i in range(0,len(feature_list)):\n",
    "    feature_list1.append(feature_list[i].ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.4/dist-packages/sklearn/svm/base.py:196: FutureWarning: The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.\n",
      "  \"avoid this warning.\", FutureWarning)\n"
     ]
    }
   ],
   "source": [
    "clf = SVC(kernel='rbf', probability=True).fit(feature_list1,labels )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 0   Actual is : 0\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n",
      "Prediction : 1   Actual is : 1\n"
     ]
    }
   ],
   "source": [
    "count=0\n",
    "for i in feature_list:\n",
    "    print(\"Prediction : \"+str(clf.predict(i)[0]),end='')\n",
    "    print(\"   Actual is : \"+str(labels[count]))\n",
    "    count=count+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
